home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Hyper / Q-R / Revert.cpt / Revert Stack / card_2884.txt < prev    next >
Text File  |  1988-01-07  |  9KB  |  279 lines

  1. -- card: 2884 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 2672
  5. -- name: Revert Card
  6. ----- HyperTalk script -----
  7. on openCard
  8.   global stackName,revertName,filePath,stacks
  9.   global ItemChosen,origCard
  10.   hide card field "Info"
  11.   if ItemChosen is "0" then
  12.     exit openCard
  13.   end if
  14.   if ItemChosen is "1" then
  15.     -- this is handled by the "Saved" button
  16.   end if
  17.   if ItemChosen is "2" then
  18.     put RenameFile((filePath & stackName),"tempStack") into errmsg
  19.     OsErr(errmsg)
  20.     put RenameFile((filePath & revertName),stackName) into errmsg
  21.     OsErr(errmsg)
  22.     put DeleteFile((filePath & "tempStack")) into errmsg
  23.     OsErr(errmsg)
  24.     put empty into revertName
  25.     put "0" into ItemChosen
  26.     go to origCard
  27.   end if
  28.   put empty into ItemChosen
  29. End openCard
  30.  
  31. --
  32. on OsErr err
  33.   -- Translate the most common ones
  34.   if err = 0 then exit OsErr
  35.   if err > 0 then -- XFCN convention
  36.     put "Parameter error with function" into errstr
  37.   else if err is -59 then
  38.     put "Problem during rename" into errstr
  39.   else if err is -54 then
  40.     put "Attempt to open locked file for writing" into errstr
  41.   else if err is -46 then
  42.     put "Volume locked by software" into errstr
  43.   else if err is -45 then
  44.     put "File locked" into errstr
  45.   else if err is -44 then
  46.     put "Volume locked by hardware" into errstr
  47.   else if err is -43 then
  48.     put "File not found" into errstr
  49.   else if err is -37 then
  50.     put "Bad volume or file name" into errstr
  51.   else if err is -36 then
  52.     put "I/O error" into errstr
  53.   else if err is -35 then
  54.     put "No such volume" into errstr
  55.   else if err is -34 then
  56.     put "Disk is full" into errstr
  57.   else if err is -49 then
  58.     put "File already open for writing" into errstr
  59.   else
  60.     put "Failed with error" && err into errstr
  61.   end if
  62.   answer errstr with "OK"
  63. end OsErr
  64.  
  65.  
  66.  
  67.  
  68.  
  69. -- part 6 (button)
  70. -- low flags: 00
  71. -- high flags: 8006
  72. -- rect: left=18 top=296 right=316 bottom=87
  73. -- title width / last selected line: 0
  74. -- icon id / first selected line: 0 / 0
  75. -- text alignment: 1
  76. -- font id: 0
  77. -- text size: 12
  78. -- style flags: 0
  79. -- line height: 16
  80. -- part name: Saved
  81. ----- HyperTalk script -----
  82. on mousedown
  83.   global ItemChosen
  84.   if the optionkey is down then
  85.     edit script of target
  86.     exit mousedown
  87.   end if
  88.   put the mouseloc into myPlace
  89.   put item 1 of myPlace - 20 into horiz
  90.   put item 2 of myPlace - 10 into vert
  91.   get PopUpMenu ("Save  ;Revert  ", 0, vert, horiz)
  92.   put it into ItemChosen
  93. end mousedown
  94.  
  95. on mouseUp
  96.   global stackName,revertName,filePath,stacks
  97.   global ItemChosen,origCard
  98.   if ItemChosen is 1 then
  99.     put (short name of this stack) into stackName
  100.     put GetPath(stackName,stacks) into filePath
  101.     put "Copy of " & stackName into revertName
  102.     put DeleteFile((filePath & revertName)) into errmsg
  103.     if errmsg is -43 then
  104.       put 0 into errmsg
  105.     end if
  106.     OsErr(errmsg)
  107.     set hilite of target to false
  108.     doMenu Save a Copy...
  109.     set hilite of target to true
  110.   end if
  111.   if ItemChosen is 2 then
  112.     set hilite of target to false
  113.     if revertName is empty or stackName is "Revert Stack" then
  114.       answer "Sorry, Unable to Revert"
  115.     else
  116.       put long name of this card into origCard
  117.       go to card "Revert Card" of stack "Revert Stack"
  118.     end if
  119.   end if
  120. end mouseUp
  121.  
  122. --
  123. function GetPath name,pathlist
  124. repeat with i = 1 to the number of lines in pathlist
  125.   if line i of pathlist is empty then next repeat -- sanity check
  126.   put line i of pathlist & name into fname
  127.   if FileModDate(fname,true) is not empty then -- found it
  128.     return line i of pathlist
  129.   end if
  130. end repeat
  131. return empty   -- file not found in pathlist
  132. end GetPath
  133.  
  134. on OsErr err
  135.   -- Translate the most common ones
  136.   if err = 0 then exit OsErr
  137.   if err > 0 then -- XFCN convention
  138.     put "Parameter error with function" into errstr
  139.   else if err is -59 then
  140.     put "Problem during rename" into errstr
  141.   else if err is -54 then
  142.     put "Attempt to open locked file for writing" into errstr
  143.   else if err is -46 then
  144.     put "Volume locked by software" into errstr
  145.   else if err is -45 then
  146.     put "File locked" into errstr
  147.   else if err is -44 then
  148.     put "Volume locked by hardware" into errstr
  149.   else if err is -43 then
  150.     put "File not found" into errstr
  151.   else if err is -37 then
  152.     put "Bad volume or file name" into errstr
  153.   else if err is -36 then
  154.     put "I/O error" into errstr
  155.   else if err is -35 then
  156.     put "No such volume" into errstr
  157.   else if err is -34 then
  158.     put "Disk is full" into errstr
  159.   else if err is -49 then
  160.     put "File already open for writing" into errstr
  161.   else
  162.     put "Failed with error" && err into errstr
  163.   end if
  164.   answer errstr with "OK"
  165. end OsErr
  166.  
  167.  
  168.  
  169.  
  170. -- part 7 (button)
  171. -- low flags: 00
  172. -- high flags: 0000
  173. -- rect: left=459 top=298 right=322 bottom=489
  174. -- title width / last selected line: 0
  175. -- icon id / first selected line: 19678 / 19678
  176. -- text alignment: 1
  177. -- font id: 0
  178. -- text size: 12
  179. -- style flags: 0
  180. -- line height: 16
  181. -- part name: Info
  182. ----- HyperTalk script -----
  183. on mouseUp
  184.   show card field "Info"
  185. end mouseUp
  186.  
  187.  
  188.  
  189. -- part 8 (field)
  190. -- low flags: 81
  191. -- high flags: 2007
  192. -- rect: left=122 top=59 right=294 bottom=369
  193. -- title width / last selected line: 0
  194. -- icon id / first selected line: 0 / 0
  195. -- text alignment: 0
  196. -- font id: 3
  197. -- text size: 9
  198. -- style flags: 0
  199. -- line height: 12
  200. -- part name: Info
  201. ----- HyperTalk script -----
  202. on mouseUp
  203.   hide card field "Info"
  204. end mouseUp
  205.  
  206.  
  207.  
  208. -- part contents for background part 3
  209. ----- text -----
  210. 9:44 PM
  211.  
  212. -- part contents for background part 2
  213. ----- text -----
  214. Tuesday, January 5, 1988
  215.  
  216. -- part contents for background part 1
  217. ----- text -----
  218. Card:
  219.  
  220. -- part contents for background part 5
  221. ----- text -----
  222. 1
  223.  
  224. -- part contents for background part 43
  225. ----- text -----
  226. 1
  227.  
  228. -- part contents for background part 45
  229. ----- text -----
  230. Total Cards:
  231.  
  232. -- part contents for background part 42
  233. ----- text -----
  234. Scripting
  235.  
  236. -- part contents for card part 8
  237. ----- text -----
  238.                        Revert Stack 1.0
  239.  
  240. Call me old-fashioned, but I miss the security of the good old Revert menu option when I'm  tweaking scripts in the stack I'm working on.  Sure, there's lots of ways to back up a stack, but inventing one more was a good excuse to try out HyperTalk.
  241.  
  242. Revert will make a duplicate copy of the stack from which it is invoked, then rename and open the backup copy when requested, trashing any changes made to the original.
  243.  
  244. Click anywhere on this text to put it away.
  245.  
  246. How to install:
  247.     Using the button tool, select and copy the 
  248. "Saved" button in the lower left hand corner of this card.
  249.     Open the stack you want to install Revert in and paste in the button.  Drag it anywhere you want.
  250.     You will also need to install the PopUpMenu,FileModDate, and DeleteFile XFCNs in your stack if they are not already there.  Copies of these XFCNs may be found in Revert.  The Developer Stack by Steve Drazga also contains these and other useful things (including a resource installer) and is available on GEnie.
  251.  
  252. How to save:
  253.     Click and hold over the radio button or the word "Saved" until the pop-up menu appears.Select the "Save" item.
  254.     When the "Save a Copy" dialog box appears, click the "Save" button.  Do not alter the name that appears in the dialog box edit field.
  255.     Once the operation is completed,the "Saved" radio button will be highlighted to indicate that the stack has been backed up.
  256.  
  257. How to revert:
  258.     Click and hold over the radio button or the word "Saved" until the pop-up menu appears.Select the "Revert" item.
  259.     When the operation is completed,the "Saved" radio button will be empty to indicate that the stack has been restored to the saved copy.
  260.     
  261. Credits:
  262.     The XFCNs used in this stack were obtained from the Developer Stack uploaded to GEnie by Steve Drazga (S.DRAZGA).  Other contributors are credited there.  Syntax and HyperTalk usage were cribbed from the HyperStation stack also by Steve Drazga.  (Thanks Steve!)
  263.  
  264. Disclaimer:
  265.     I've tried to cover all the obvious things that could occur during execution of Revert.  Nevertheless, be cautious when using it.  I'd like to hear about anything you notice during its use.
  266.  
  267. Request for ideas, suggestions:
  268.     This is my first effort using HyperTalk and I know that there are many improvements which can be made.  If anyone has any suggestions or wishes to point out other HyperTalk methods that I could use, they would be very gratefully received. 
  269.  
  270. Name and address:
  271.     
  272.     Rick Riccelli
  273.     5338 Durwood Dr.
  274.     Swartz Creek, Mich   48473
  275.     (313) 635-3924
  276.  
  277.     GEnie:  R.RICCELLI
  278.  
  279.